package com.cesce.batch.cobros.validation;


import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.springframework.batch.item.validator.ValidationException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springmodules.validation.valang.functions.AbstractFunction;
import org.springmodules.validation.valang.functions.Function;

import com.cesce.batch.cobros.dominio.Comunicados;
import com.cesce.batch.cobros.reverse.Cobcomunicados;
import com.cesce.batch.cobros.reverse.Cobformatofechacobros;
import com.cesce.batch.cobros.reverse.Cobparametros;
import com.cesce.batch.cobros.reverse.Cobregistro;


public class IsProcessedValidation extends AbstractFunction {
	
		protected final Log logger = LogFactory.getLog(getClass());
		

	    public IsProcessedValidation(Function[] arguments, int line, int column) {
	        super(arguments, line, column);
	        definedExactNumberOfArguments(1);
	    }
	
	    
		@SuppressWarnings("unchecked")
		protected Object doGetResult(Object target) throws Exception {
			BigDecimal idregistro = (BigDecimal) getArguments()[0].getResult(target);

			BigDecimal count = Cobcomunicados.countCobcomunicadosesByRegistro(idregistro);
			
			boolean result=count.compareTo(new BigDecimal(0))>0; 
			
			if(result) throw new ValidationException("Registro procesado anteriormente");
			
			return new Boolean(result);
		}

}

